<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>测测你的宅腐基指数-测试结果及转发</title>

    <script type="text/javascript" src="script/jquery.min.js"></script>

    <script type="text/javascript" src="script/imageScroller.js"></script>

    <link href="css/main.css" type="text/css" rel="stylesheet" />

    <script type="text/javascript" language="javascript">
        (function() {
            var _skin, _jQuery;
            document.write('<scr' + 'ipt src="script/dialogs/artDialog.source.js?skin=' + (_skin || 'blue') + '"></sc' + 'ript>');
            window._isDemoSkin = !!_skin;
        })();

    </script>
    <script type="text/javascript" language="javascript" src="script/dialogs/artDialog_helper.js"></script>
    <script type="text/javascript">
        function showSucceedMsg(title, msg) {
            var dialog = art.dialog({
                title: title,
                content: msg,
                background: '#CCC',
                icon: 'succeed',
                ok: true,
                zIndex: 9999
            });
        }

        function showErrMsg(title, msg) {
            var dialog = art.dialog({
                title: title,
                content: msg,
                background: '#CCC',
                icon: 'warning',
                cancelVal: '关闭',
                cancel: true,
                zIndex: 9999
            });
        }


        String.prototype.getQueryString = function(name) {
            var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"), r;
            if (r = this.match(reg)) return unescape(r[2]);
            return "";
        };

        $(document).ready(function() {
            var resultscore = window.location.search.getQueryString("score");
            
            //根据选项获得的分数,获取结果,并绑定到页面上
            $.get("TweetsHandler.ashx?action=load&resultscore=" + resultscore + "&" + Math.random(), function(jsonhtml) {
                var data = eval("(" + jsonhtml + ")");
                //绑定获取的分数
                $("#resultscore").val(resultscore);
                //绑定获取到的评测结果
                $("#textinput").val(data.ResultContent);
                //检查可录入的字数
                $("#textinput").keydown();

                //绑定评测结果对应的图片
                $(".imgbox").append("<img src='" + data.ResultPic + "' alt='' />");

            }, "json");
            
            //加载关注的微博用户
            $.get("TweetsHandler.ashx?action=loadbilateral&" + Math.random(),
                function(jsonhtml) {
                    //解析取道的json对象
                    var data = eval("(" + jsonhtml + ")");
                    
                    //清空图像列表控件
                    $("#friendbox_ul").html("");
                    
                    //加载关注好友的图像
                    $.each(data.users, function(index, item) {
                    $("#friendbox_ul").append("<li title='" + item.screen_name + "' ><img src='" + item.profile_image_url + "' alt='" + item.screen_name + "' width=\"32\" height=\"32\"/></li>");
                });
                    //给图像列表绑定事件
                    $(".friendbox li").click(function() {
                        var content = $("#textinput").val();
                        var displayName = $(this).attr("title");
                        if (content.indexOf(" @" + displayName) == -1) {
                            if ($("#textinput").val().length + (" @" + displayName).length < 140) {
                                $("#textinput").val(content + " @" + displayName);
                                $("#textinput").keydown();
                            }
                            else {
                                showErrMsg("提示", "你的美肌愿望太长了");
                                return false;
                            }
                        }
                    });
                }, "json");


            //绑定选择事件
            $(".chkbox").click(function() {
                if ($(this).hasClass('chkon')) {
                    $(this).find(".chkValue").attr("checked", false);
                    $(this).removeClass('chkon');
                } else {
                    $(this).find(".chkValue").attr("checked", true);
                    $(this).addClass('chkon');
                }
                return true;
            });

            //绑定发送微博事件
            $(".btn_post").click(function() {

                if ($("#textinput").val() == "") {
                    showErrMsg("提示", "请选择好友");
                    return;

                }

                if ($("#textinput").val().length >= 140) {
                    showErrMsg("提示", "选择了过多的好友");
                    return;
                }
                
                //提交并发布微博
                var url = "TweetsHandler.ashx?action=submit&" + Math.random();
                $.post(url, { "resultscore": $("#resultscore").val(), "resultcontent": $("#textinput").val(),"addfriend": $(".chkValue").attr("checked")  }, function(data) {
                    switch (data.error) {
                        case 0:
                            showSucceedMsg("提示", "微博发布成功");
                            document.location.href = data.href;
                            break;
                        case 1:
                            showErrMsg("提示", data.msg);
                            break;
                        case 2:
                            showErrMsg("提示", "请重新登录");
                            document.location.href = "index.html";
                            break;
                    }

                }, "json");
            });

            $(".friendbox").imageScroller({
                next: "btn_toright",
                prev: "btn_toleft",
                frame: "friendbox_ul",
                width: 36,
                child: "li",
                auto: false
            });

            //文字数量检查函数
            $(".inputtips").html("还可以输入<b>" + (140 - $("#textinput").val().length) + "</b>个字");
            $("#textinput").keydown(function() {
                $(".inputtips").html("还可以输入<b>" + (140 - $("#textinput").val().length) + "</b>个字");
            });


        });
    </script>

</head>
<body>
    <div id="wrapper" class="body03">
        <a href="http://www.e-lining.com/" class="pos b_logo" title="进入李宁官方网站"></a>
        <div class="pos imgbox">
            </div>
        <a href="#" id="btn_toleft" class="pos" title="向左翻"></a><a href="#" id="btn_toright"
            class="pos" title="向右翻"></a>
        <div class="pos friendbox" id="friendbox_ul_div">
            <ul id="friendbox_ul">
            </ul>
        </div>
        <div class="pos txtbox">
            <textarea class="textarea" id="textinput"></textarea>
        </div>
        <p class="pos inputtips">
            还可以输入 <b>140</b> 个字</p>
        <a href="#" class="pos btn_post" title="发布微博"></a><a href="case.html" class="pos btn_back"
            title="重新测试"></a><a class="pos chkbox chk21">
                <input type="checkbox" class="chkValue" name="chk" value="1" /></a>
    </div>
    <input type="hidden" id="resultscore" />
</body>
</html>
